<?php
class AppHelper extends Helper {
	
	function url($url = null, $full = false) {

		if(!isset($url['language'])){

			if(isset($this->params['language'])){
				$url['language'] = $this->params['language'];
			}else{
				$url['language'] = Configure::read('Config.language');
			}
		}	
		return parent::url($url, $full);
	}
	
	/**
	 * 
	 * CSS style block in header
	 * @param unknown_type $script
	 * @param unknown_type $options
	 */
	
	function styleBlock($script, $options = array()) {
		$options += array('safe' => false, 'inline' => true);
		if ($options['safe']) {
			$script  = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
		}
		$inline = $options['inline'];
		unset($options['inline'], $options['safe']);
		$attributes = $this->_parseAttributes($options, ' ', ' ');
		if ($inline) {
			return sprintf('<style type="text/css"%s>%s</style>', $attributes, $script);
		} else {
			$view =& ClassRegistry::getObject('view');
			$view->addScript(sprintf('<style type="text/css"%s>%s</style>', $attributes, $script));
			return null;
		}
	}

	/**
	 * JQuery dialog
	 * 
	 * @param unknown_type $object
	 * @param unknown_type $params
	 * @param unknown_type $options
	 */
	public function dialog($object,$params=array(), $options = array()){
		$options += array('safe' => false, 'inline' => false);
		$patams = json_encode($params);
		$script = "$(document).ready(function(){
				$( '{$object}' ).dialog({$patams});
			});";
					
		if ($options['safe']) {

			$script  = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
		}
		$inline = $options['inline'];
		unset($options['inline'], $options['safe']);
		$attributes = $this->_parseAttributes($options, ' ', ' ');
		if ($inline) {
			return sprintf('<script type="text/javascript"%s>%s</script>', $attributes, $script);
		} else {
			$view =& ClassRegistry::getObject('view');
			$view->addScript(sprintf('<script type="text/javascript"%s>%s</script>', $attributes, $script));
			return null;
		}		
	}
}